﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Utility
{
    class DBAccess
    {                
        private SqlConnection GetConnection()
        {
            return new SqlConnection(@"Data Source=YAKATA-PC\SQLEXPRESS;Initial Catalog=DienThoaiDiDong;Integrated Security=True");//server=YAKATA-PC;database=DienThoaiDiDong;user=sa;password=guardianangel
        }

        public DataSet ExecSQLDataSet(string sql)
        {
            DataSet ds = new DataSet();
            SqlConnection con = GetConnection();
            SqlDataAdapter da = new SqlDataAdapter(sql, con);
            da.Fill(ds);
            return ds;
        }        

        public int ExecNonQuery(string sql)
        {
            int res = 0;
            SqlConnection con = GetConnection();
            SqlCommand cmd = new SqlCommand(sql, con);
            con.Open();

            res = cmd.ExecuteNonQuery();
            res = 1;
            con.Close();
            return res;
        }

    }
}
